package com.yanqu.road.server.cmd.activity.newyear2023.redpacket.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FireWorkProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_FIREWORK_CROSS_DATA_ALL_SYNC, desc = "用户数据同步")
public class CrossFireWorkSyncAllUserDataCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FireWorkProto.CrossFireWorkUserDataSyncMsg reqMsg = FireWorkProto.CrossFireWorkUserDataSyncMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        for(FireWorkProto.CrossFireWorkUserDataTempMsg dataMsg : reqMsg.getDataList()){
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(dataMsg.getUserId());
            if(player != null){
                FireWorkProto.FireWorkCrossDataSyncMsg.Builder userMsg = FireWorkProto.FireWorkCrossDataSyncMsg.newBuilder();
                userMsg.setActivityId(activityId);
                userMsg.setOpenHistoryCount(dataMsg.getOpenCount());
                userMsg.setOpenStatusNum(dataMsg.getOpenNum());
                userMsg.setCanRob(dataMsg.getCanRob());
                player.sendPacket(Protocol.U_FIREWORK_CROSS_DATA_SYNC, userMsg);
            }
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
